// clipboard.js 复制功能
import Vue from 'vue'
import ClipBoard from 'clipboard'

function ClipBoardSuccess () {
  Vue.prototype.$toast.success('复制成功')
}

function ClipBoardError () {
  Vue.prototype.$toast.fail('复制失败')
}

export default function (text, event, isSuccess = ClipBoardSuccess, isError = ClipBoardError) {
  const clipBoard = new ClipBoard(event.target, {
    text: () => {
      return text
    }
  })

  clipBoard.on('success', () => {
    isSuccess()
    clipBoard.destroy()
  })
  clipBoard.on('error', () => {
    isError()
    clipBoard.destroy()
  })
  clipBoard.onClick(event)
}
